import Vue from "vue";
import VueRouter from "vue-router";
import VueResource from "vue-resource";
import routes from "./router/router";
import navs from "./router/router";
import MuseUI from "muse-ui";
import Lazyload from 'vue-lazyload';
import theme from 'muse-ui/lib/theme';
import Vlf from 'vlf';
import vueTap from 'v-tap';
import store from './store'
import NProgress from 'muse-ui-progress';
Vue.config.productionTip = false;
Vue.use(NProgress, {
  color: '#ffb48e'
});
Vue.use(Vlf);
Vue.use(vueTap);
const store = new Vuex.Store({
  state: {
    count: 0
  },
  mutations: {
    increment(state) {
      state.count++
    }
  }
})

// this.$vlf.createInstance({
//   storeName: 'user'
// }).then((store) => {
//   store.setItem('key', [])
//   store.length().then((keys) => {
//     console.log(keys)
//   })
//   store.iterate((value, key, num) => {
//     return [key, value]
//   }).then((result) => {
//     console.log(result)
//   })
// })

theme.use('dark');
theme.add('teal', {
  primary: '#ff4081',
  secondary: '#ff4081',
  success: '#4caf50',
  warning: '#fdd835',
  info: '#2196f3',
  error: '#f44336',
  track: '#bdbdbd',
  text: {
    primary: 'rgba(0, 0, 0, 0.87)',
    secondary: 'gba(0, 0, 0, 0.54)',
    alternate: '#fff',
    disabled: 'rgba(0, 0, 0, 0.38)',
    hint: 'rgba(0, 0, 0, 0.38)' // 提示文字颜色
  },
  divider: 'rgba(0, 0, 0, 0.12)',
  background: {
    paper: '#fff',
    chip: '#e0e0e0',
    default: '#fafafa'
  }
}, 'light');
theme.use('teal');

Vue.use(MuseUI);
// Vue.$messagebox = Vue.prototype.$messagebox = MessageBox;
// Vue.$toast = Vue.prototype.$toast = Toast;
Vue.use(Lazyload, {
  preLoad: 1.5,
  error: './../../public/images/error.png',
  loading: './../../public/images/loading.gif',
  attempt: 1,
  observer: true,
  // optional
  observerOptions: {
    rootMargin: '0px',
    threshold: 0.1
  }
});

import FastClick from "fastclick";
import {
  cookie
} from './commponent/index'
FastClick.attach(document.body);
// if ("addEventListener" in document) {
//   document.addEventListener(
//     "DOMContentLoaded",
//     function () {
//       FastClick.attach(document.body);
//     },
//     false
//   );
// }
Vue.use(VueRouter);
Vue.use(VueResource);
Vue.config.productionTip = false;
const router = new VueRouter({
  routes,
  mode: "hash",
  strict: process.env.NODE_ENV === "production"
});
// router.beforeEach((to, from, next) => {
//   iView.LoadingBar.start();
//   next();
// });

// router.afterEach(route => {
//   iView.LoadingBar.finish();
// });
// router.beforeEach((to, from, next) => {
//   if (to.path == "/login") {
//     next();
//   } else {
//     let userName = cookie.getCookie("userName");
//     if (!userName && to.path == "/home/main/post") {
//       next({ path: "/login" });
//     } else {
//       next();
//     }
//   }
// });
// router.beforeEach((to, from, next) => {
//   NProgress.start();
//   next();
// });

// router.afterEach(route => {
//   NProgress.done();
// });
Vue.prototype.title = '';
new Vue({
  components: {},
  data: {
    msg: "app"
  },
  router,
  store,
  watch: {
    $route(to, from) {
      if (to.name == 'login') {
        cookie.set('backPath', from.fullPath, {
          expires: 0.05
        });
      }
    }
  },
}).$mount("#app");
